package com.hoolai.synroom.dispatcher;

import com.google.protobuf.Descriptors.FieldDescriptor.JavaType;

public class ProtoBufJavaTypeComparator {
    
    private static Class convertToJavaBaseType(JavaType javaType) {
        switch (javaType) {
        case BOOLEAN:
            return boolean.class;
        case DOUBLE:
            return double.class;
        case INT:
            return int.class;
        case LONG:
            return long.class;
        case FLOAT:
            return float.class;
        case STRING:
            return String.class;
        default:
            //TODO need log
            throw new RuntimeException("unsupport java type");
        }
    }
    
    public static boolean isMatch(JavaType javaType, Class clazz) {
        if(clazz == convertToJavaBaseType(javaType) || clazz == convertToJavaClassType(javaType)) {
            return true;
        }
        return false;
    }
    
    private static Class convertToJavaClassType(JavaType javaType) {
        switch (javaType) {
        case BOOLEAN:
            return Boolean.class;
        case DOUBLE:
            return Double.class;
        case INT:
            return Integer.class;
        case LONG:
            return Long.class;
        case FLOAT:
            return Float.class;
        case STRING:
            return String.class;
        default:
            //TODO need log
            throw new RuntimeException("unsupport java type");
        }
    }
}
